home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: serverActions.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:41 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "pool.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "semaphore.h"
- #include "link.h"
- #include "lsn.h"
- #include "latch.h"
- #include "bf.h"
- #include "volume.h"
- #include "trans.h"
- #include "openlog.h"
- #include "logrecs.h"
- #include "logaction.h"
- #include "bitvec.h"
- #include "adminmsg.h"
- #include "trans_intfuncs.h"
- #include "trans_extfuncs.h"
- #include "lm_extfuncs.h"
- #include "log_extfuncs.h"
- #include "msg_funcs.h"
- #include "io_extfuncs.h"
- #include "trans_globals.h"
- #include "thread_globals.h"
- #include "admin_globals.h"
- #include "admin_funcs.h"
- #include "io_globals.h"
- #include "distr.h"
- #include "distr_globals.h"
- #include "distr_intfuncs.h"
-
- /*
- * For write timing of log pages
- */
- extern FOUR StatTotalTime_usec;
- extern FOUR StatPagesWritten;
- extern FOUR StatWriteCalls;
- extern FOUR StatClientMsgs;
-
- extern FILE *sm_ErrorStream;
-
- int
- serverPrepareTrans (
- register TRANSREC *transRec,
- VOTE *vote
- )
- {
-
- DIRTYPAGELOGINFO *dirtyInfo = DirtyPageLogInfo;
- int numDirtyPages;
- LOGRECORDINFO recordInfo;
- FORCEMARK forceMark;
-
- TRPRINT(TR_TRANS, TR_LEVEL_2, ("tid:%d", GETTID(transRec)));
-
- if (PrintExtraStats && StatPagesWritten > 0) {
- fprintf(sm_ErrorStream, "PreCommit write times: time=%d #pages=%d #writeCalls=%d clientMsgs=%d\n", StatTotalTime_usec/1000, StatPagesWritten, StatWriteCalls, StatClientMsgs);
- StatPagesWritten = StatWriteCalls = StatClientMsgs = StatTotalTime_usec = 0;
- }
-
- /*
- * Temporarily make the transaction active in order to log
- * page deallocations.
- */
- transRec->transState = T_ACTIVE;
-
- initializeList(&(transRec->pendingBitmapList));
-
- /*
- * deallocate all temporary files and pages
- * Note: this can be done at prepare time because
- * it shall be done regardless of commit/abort
- */
- deallocTempFilesPages(transRec);
- /*
- * add all the pages in the all the files to be destroyed
- * to the list of pages to deallocate
- */
- if (transDeallocFilePages(transRec) != esmNOERROR) {
- /* clean up dealloc info */
- SM_ERROR(TYPE_CRASH, esmINTERNAL);
- }
-
- /*
- * Log all pending page deallocations
- */
- if (logTransDeallocPages(transRec, &(transRec->pendingBitmapList)) != esmNOERROR) {
- /*
- * For now, just crash, but we should really clean things up
- * and abort the transaction. Clean-up is complicated by
- * the bitmap and volume header pages which are pinned with
- * pending operations.
- */
- SM_ERROR(TYPE_CRASH, esmINTERNAL);
- }
-
- /*
- * Restore transaction to the quiesced state
- */
- transRec->transState = T_QUIESCE;
-
- /*
- * If the transaction generated some log records, make sure they
- * are flushed.
- */
- if (transRec->logRecordCount > 0) {
-
- /*
- * Make sure only one thread is using the global
- * variable DirtyPageLogInfo at a time.
- */
- if (waitSemaphore(&DirtyPageLogInfoSemaphore)) {
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- }
-
- /*
- * Fill an array of information for all pages dirtied by
- * this transaction since the last checkpoint.
- */
- numDirtyPages = listDirtyTransPages(transRec, dirtyInfo);
- PRINT_PROGRESS(("logging %d pages as dirty since last checkpoint\n", numDirtyPages));
-
- /*
- * Generate a log record containing the dirty page info
- */
- recordInfo.action = 0;
- recordInfo.type = LOG_REC_TYPE_DIRTYPAGELIST;
- recordInfo.imageCount = 1;
- recordInfo.actionPid = NULL;
- recordInfo.actionLRC = NULL;
- recordInfo.imageSize[0] = numDirtyPages * sizeof(DIRTYPAGELOGINFO);
- recordInfo.imageData[0] = (char *) dirtyInfo;
- recordInfo.nextUndoLSN = NULL_LSN;
- recordInfo.flags = REDO_ONLY;
-
- /*
- * write the record to the log
- */
- if ((forceMark = writeNonTransLogRecord(&recordInfo, NULL, NOFLAGS)) < 0) {
- /* caller will abort */
- signalSemaphore(&DirtyPageLogInfoSemaphore);
- return(esmFAILURE);
- }
-
- /*
- * Done with DirtyPageLogInfo
- */
- signalSemaphore(&DirtyPageLogInfoSemaphore);
-
- /*
- * we must log the prepare record
- */
- if (server_LogPrepare(transRec, vote) < esmNOERROR) {
- /* caller will abort */
- return(esmFAILURE);
- }
-
- TRPRINT(TR_DISTR|TR_TRANS, TR_LEVEL_2,
- ("server : wrote T_PREPARED : tid:%d", GETTID(transRec)));
-
- if (*vote == READVOTE) {
- /*
- * read-only transaction
- * forget it and return success
- */
- if (serverCommitTrans(transRec) != esmNOERROR) {
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- }
- return(esmNOERROR);
- }
-
- } else if (!transRec->loggingOn) {
- /*
- * Logging is turned off - return NOVOTE for now
- * TODO: maybe allow this - will not be able to log
- * COMMIT though
- */
- *vote = NOVOTE;
- SM_ERROR(TYPE_USER, esmLOGGINGOFF);
- /* caller will abort */
- return(esmFAILURE);
-
- } else {
-
- SM_ASSERT(LEVEL_3, LIST_EMPTY(&(transRec->clientDirtyList)));
-
- /*
- * read-only transaction
- * forget it and return success
- */
- if (serverCommitTrans(transRec) != esmNOERROR) {
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- }
- }
-
- return(esmNOERROR);
- }
-
-
-
- int
- serverCommitTrans (
-
- register TRANSREC *transRec
- )
- {
- TRPRINT(TR_TRANS, TR_LEVEL_2, ("tid:%d", GETTID(transRec)));
-
- if (PrintExtraStats && StatPagesWritten > 0) {
- fprintf(sm_ErrorStream, "PreCommit write times: time=%d #pages=%d #writeCalls=%d clientMsgs=%d\n", StatTotalTime_usec/1000, StatPagesWritten, StatWriteCalls, StatClientMsgs);
- StatPagesWritten = StatWriteCalls = StatClientMsgs = StatTotalTime_usec = 0;
- }
-
- #ifdef DEBUG
- if (DebugCrashLoc == 14)
- admin_ShutServer(0);
- #endif DEBUG
-
- /*
- * we must log the commit record
- */
- if (server_LogCommit(transRec) < esmNOERROR) {
-
- SM_ERROR(TYPE_CRASH, esmINTERNAL);
-
- }
- TRPRINT(TR_DISTR|TR_TRANS, TR_LEVEL_2,
- ("server : wrote T_COMMIT : tid:%d", GETTID(transRec)));
-
- /*
- * Perform all pending page deallocations
- */
- if (deallocTransPages(transRec, &(transRec->pendingBitmapList)) != esmNOERROR) {
-
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- }
-
- SM_ASSERT(LEVEL_3, LIST_EMPTY(&(transRec->fileDeallocList)));
- SM_ASSERT(LEVEL_3, LIST_EMPTY(&(transRec->pageDeallocList)));
- SM_ASSERT(LEVEL_3, LIST_EMPTY(&(transRec->pendingBitmapList)));
-
- /*
- * Make sure all bitmaps are consistent after any
- * deallocation/allocation
- */
- SM_ASSERT(LEVEL_3, io_CheckAllVolumes() == esmNOERROR);
-
- /*
- * check to see if there are any log records
- * that are written for this transaction
- */
- if (transRec->lastLSN != 0) {
- /*
- * take the record off the log queue
- */
- removeLogList(transRec);
- }
-
- /*
- * free all the locks
- */
- unlockAll(transRec, esmTRANSCOMMITTED);
-
- /*
- * free the structures
- */
- freeTransVolRecs(transRec);
-
- /*
- * give back the transaction record
- * reset the state to T_INACTIVE
- */
- freeTransRec(transRec);
-
- TotalCommits++;
-
- /*
- * return with success
- */
- return(esmNOERROR);
- }
-